/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.base.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.base.dao.StoreCardTemplateProductDetailDao;
import com.chlitina.store.modules.base.entity.StoreCardTemplateProduct;
import com.chlitina.store.modules.base.entity.StoreCardTemplateProductDetail;

/**
 * 产品充值卡模板产品Service
 * @author liujiang
 * @version 2013-11-03
 */
@Component
@Transactional(readOnly = true)
public class StoreCardTemplateProductDetailService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StoreCardTemplateProductDetailService.class);
	
	@Autowired
	private StoreCardTemplateProductDetailDao storeCardTemplateProductDetailDao;
	
	public StoreCardTemplateProductDetail getByPK(Long tid, Long pid) {
		return storeCardTemplateProductDetailDao.findByPK(tid, pid);
	}
	
	public Page<StoreCardTemplateProductDetail> find(Page<StoreCardTemplateProductDetail> page, StoreCardTemplateProductDetail storeCardTemplateProductDetail) {
		DetachedCriteria dc = storeCardTemplateProductDetailDao.createDetachedCriteria();
		dc.addOrder(Order.desc("id"));
		return storeCardTemplateProductDetailDao.find(page, dc);
	}
	
	public List<StoreCardTemplateProductDetail> findBy(StoreCardTemplateProduct storeCardTemplateProduct) {
		DetachedCriteria dc = storeCardTemplateProductDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq("storeCardTemplateProduct", storeCardTemplateProduct));
		dc.addOrder(Order.asc("id"));
		return storeCardTemplateProductDetailDao.find(dc);
	}
	
	@Transactional(readOnly = false)
	public void save(StoreCardTemplateProductDetail storeCardTemplateProductDetail) {
		storeCardTemplateProductDetailDao.save(storeCardTemplateProductDetail);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long tid, Long pid) {
		storeCardTemplateProductDetailDao.delete(tid, pid);
	}
	
}
